package org.study.stock.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.study.stock.service.StockService;

import java.util.HashMap;
import java.util.Map;

/**
 * @author heshaohua
 * @version 1.0.0
 * @date 2024年07月31日 16:47:00
 */
@RestController
@RequestMapping("/core")
@Slf4j
public class StockController {

    private final StockService stockService;

    public StockController(StockService stockService) {
        this.stockService = stockService;
    }

    /**
     * 扣减库存
     * @return
     */
    @PostMapping("/deduct")
    public Object deduct(@RequestBody Map<String, String> param){
        log.info("xxxxx");

        this.stockService.deduct(param);

        Map<String, Object> resultData = new HashMap<>(8);
        resultData.put("code", 0);
        resultData.put("msg", "success");

        return resultData;
    }

}